#!/usr/bin/perl
#
# Remove a counter administrator
#
use Counter::CGI;
use CGI::Carp;
use Apache::Htpasswd;

$q = new Counter::CGI;

$remove_admin=$q->param("adminaccount");
if (!$remove_admin) { error("Admin account name not given"); }

if (!$ENV{REMOTE_USER}) {
    error("Not logged in");
}

# warn "Removing admin account $remove_admin by $ENV{REMOTE_USER}\n"; 
#$pwf = new Apache::Htpasswd("$ENV{COUNTER_ROOT}/access/users");
$pwf = new Apache::Htpasswd("/home/counter/access/users");
$pwf->htDelete($remove_admin)
    || error("Removing admin account failed. Admin account does not exist?");


print $q->redirect("/administration/");

sub error {

    my $msg = shift;

    print <<EoF;
Content-type: text/html

<html><head><title>Admin account removal error</title>
</head><body>
<h1>Error during admin account removal </h1>
The error was $msg ($ENV{REMOTE_USER})
</body>
</html>
EoF
    exit(0);

}

    
